package org.yray.io.gcdemo;

import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;

import java.lang.management.ManagementFactory;
import java.lang.management.PlatformManagedObject;
import java.lang.reflect.Method;

public class Dump {
    public static void main(String[] args) {
        Class<?> diagnosticMXBeanClass = ClassUtils
                .resolveClassName("com.sun.management.HotSpotDiagnosticMXBean", null);
        Object diagnosticMXBean= ManagementFactory
                .getPlatformMXBean((Class<PlatformManagedObject>) diagnosticMXBeanClass);
        Method dumpHeapMethod = ReflectionUtils.findMethod(diagnosticMXBeanClass, "dumpHeap", String.class,
                Boolean.TYPE);
        ReflectionUtils.invokeMethod(dumpHeapMethod, diagnosticMXBean, "D:\\test\\dump_live.hprof", true);
        ReflectionUtils.invokeMethod(dumpHeapMethod, diagnosticMXBean, "D:\\test\\dump_dead.hprof", false);
    }
}
